
<!--layer弹出层批量操作-->
 <!-- nav -->

   <div  id ="operationBatch" style="display: none;">
    <nav ui-nav class="navi" ng-include="'src/app/channel/epgManager/operation_batch.html'"></nav>
   </div>
    <!-- nav -->

<div class="bg-light lter b-b wrapper-md">
  <h1 class="m-n font-thin h3">EPG管理</h1>
</div>
<div class="wrapper-md">
<div class="row">
 <div class="col-sm-2" >
   <!-- 左边菜单-->

    <div id ="selectDate" style="width: 180px">
    <nav ui-nav class="navi" ng-include="'src/app/channel/epgManager/selectDate.html'"></nav>
    </div>



 </div>

 <div class="col-sm-10">
  <div class="panel panel-default">
    
    <div  ng-controller="dataTablesCtrl">
    <div class="panel-heading">
      <p class="text-muted"><span class="label label-info">频道:{{clName}}</span></p> 
    </div>
   <div class="row">

 <div class="col-sm-12" >
 <div class="panel-heading">

<a href="javascript:void(0);" ng-click="goAdd();"><button class="btn btn-default btn-sm "><i class="fa fa-plus fa-lg"></i>&nbsp; 新增</button></a>

<a href="javascript:void(0);" ng-click="goEdit();" ><button class="btn btn-default btn-sm "><i class="fa fa-edit fa-lg"></i>&nbsp; 编辑</button></a>

<a href="javascript:void(0);" ng-click="goRemove();" ><button class="btn btn-default btn-sm "><i class="fa fa-trash-o fa-lg"></i>&nbsp; 删除</button></a>
<button class="btn btn-default btn-sm " ng-click="goBack()"><i class="fa fa-mail-reply fa-lg"></i>&nbsp; 返回</button>
<br/>
<a href="javascript:void(0);" ng-click="goAddAll();"><button class="btn btn-default btn-sm "><i class="fa fa-plus fa-lg"></i>&nbsp; 批量导入</button></a>
<button class="btn btn-default btn-sm " ng-click="generateProgram()">生成节目单</button>

<!--隐藏域-->
<input type="hidden" id ="optIds" name="optIds">
 <input type="hidden" name="channelName" id="channelId" />
</div>
 </div>


 </div>
      <table id="myTable" class="table  m-b-none table-hover">
      </table>  
    </div>
   
  </div>
  </div>
  </div>

</div>


<!--样式-->
<style type="text/css">  
    div#rMenu {position:absolute; visibility:hidden; top:0; background-color: #555;text-align: left;padding: 2px;}  
    div#rMenu a{  
        cursor: pointer;  
        list-style: none outside none;  
    }  

.selected {
  background-color: #DFF0D8;
}
  
/* dataTables列内容居中 */
.table>tbody>tr>td{
        text-align:center;
}

/* dataTables表头居中 */
.table>thead:first-child>tr:first-child>th{
        text-align:center;
}
</style>
<!--样式-->


<script type="text/javascript">

var cId = 0;

//angularjs总控制器
app.controller('dataTablesCtrl', function($scope, $http,$state, $stateParams,$http,$window) {

   //陆游参数
      cId = $stateParams.cId;

//进入编辑页面
   $scope.goEdit = function () {
  var optIds = $('#optIds').val();
     if(''==optIds){
    top.layer.msg('请至少选择一项', {icon: 6});
       return false;
  }
  if(optIds.indexOf(",") != -1){
    top.layer.msg('编辑只能选择一项', {icon: 6});
    return false;
  }
        $state.go('app.epgManager.epgManagerEdit', {epgId: optIds,cId:cId});
    };

    //新增操作
     $scope.goAdd = function () {
 
        $state.go('app.epgManager.epgManagerEdit', {cId: cId});
    };



    //返回按钮：开始
$scope.$window = $window;
    $scope.goBack = function() {
      $window.history.go(-1);
    };
//返回按钮：结束

//获取显示频道操作
var url =  document.URL;
  var arr =  url.split("/"); 
   channelId = arr[arr.length-1];
    
//获取频道信息
  
  var getprogramUrl = API_URL+"channel_info?query=delflag:0,Id:"+channelId;

  var channel = MY_ASYNC_AJAX(getprogramUrl)[0];

  $scope.clName = channel.ChannelName;

  //获取频道结束

//批量操作
  $scope.goAddAll=function(){
 
    top.layer.open({
        type: 1,
        title: '批量增加',
        shadeClose: false,
        anim: 1,
        shift: 4,
        shade: [0.5],
        fix: true,
        maxmin: true,
        move: true,
        area: ['800px', '500px'],
        content: $('#operationBatch')
      });
   }

   //生成节目单
   $scope.generateProgram=function(){
    alert("生成完毕。。。")
   }


//进入删除操作
   $scope.goRemove = function () {
  var optIds = $('#optIds').val();

     if(''==optIds){
    top.layer.msg('请至少选择一项', {icon: 6});
       return false;
    }

    top.layer.confirm('您确定删除这些信息吗', function(index){

    var postInfoUrl = API_URL+"channel_epg";

    var optArrs = optIds.split(',');

    for(var i = 0;i< optArrs.length;i++ ){

         var infoUrl = API_URL+"channel_epg?query=delflag:0,Id:"+optArrs[i];

          var formData =  MY_ASYNC_AJAX(infoUrl)[0];
         
          formData.Delflag = "1";

     $.ajax({
         url : postInfoUrl+'/'+optArrs[i],
        type : 'delete',
         data: JSON.stringify(formData),
           cache : false,
         success : function(data) {
          
          }
        });

      }
        var table = $('#myTable').DataTable();

        top.layer.msg('删除成功');
       table.ajax.reload().draw();


  });
    
    };


});




function checkOne(){
  var optIds = '';
  $("input[name='ids']:checkbox:checked").each(function(){ 
      optIds+=$(this).val() +',';
       });
   if(''!=optIds){
        optIds = optIds.substring(0,optIds.length-1);
      }
$('#optIds').val(optIds);

  console.log($('#optIds').val());
}




    $(document).ready(function(){

      var url =  document.URL;
      var arr =  url.split("/"); 
       chId = arr[arr.length-1];
    
        //获取频道
        var getprogramUrl = API_URL+"channel_info?query=delflag:0,Id:"+chId;

        var channel = MY_ASYNC_AJAX(getprogramUrl)[0];
        var channelName = channel.ChannelName;

      var dtUrl =  API_URL+"channel_epg?query=delflag:0,ChannelId:"+chId;


 //初始化dataTable
     var table =  $('#myTable').DataTable({
            ajax: {
                url: dtUrl,
                dataSrc: ""
                
            },
         deferRender:true,
         Processing:true,
          buttons: [
        {
            extend: 'collection',
            text: 'Export',
            buttons: [ 'csv-flash', 'xls-flash', 'pdf-flash' ]
        }
    ],
            //默认最后一列（最后更新时间）降序排列
            order: [[6, "desc"]],
         
            //行创建完成后回调
            rowCallback: function (row, data, index) {
               
            },
                    aoColumns: [
                    { data : "Id",
                    title: "<input type='checkbox' id='allChecked' name='allChecked' />",
                  orderable: false , 
              render : function(data, type, full, meta) {
            return '<input type="checkbox" value="'+ data + '" name="ids" onclick="checkOne()"/>';
           }},
           { data: "Id",
            title: "ID"
          },
         
         { data: "ProgramName" ,
            title: "节目名称"
       },
     /*       { data: "ProgramIntroduction"  ,
              title: "节目简介" },*/
                { data: "BeginTime" ,
            title: "开始时间",
                render: function (data, type, row, meta) {

                        return getDateTime(data);
                    }
       },
            { data: "EndTime"  ,
              title: "结束时间" ,
                render: function (data, type, row, meta) {

                        return getDateTime(data);
                    }
            },

         { data: "UpdateTime"   ,

         title: "更新时间",
                    render: function (data, type, row, meta) {

                        return getDateTime(data);
                    }}
     ],
            columnDefs: [
          
                {
                    targets: 6,
                    data: null,
                    title: "操作",
                    render: function (data, type, row, meta) {

                        var href = '';

                    
                            href += "&nbsp; <a href='#/app/epgManager/epgManager/edit/"+cId+"/"+row.Id+"'>";
                          href += "<i  title='编辑' class='fa fa-edit fa-lg'></i></a>";
                          
                          href += "&nbsp;  <a href='javascript:void(0);' onclick=goDelete("
                              + row.Id
                              + ")>";
                          href += "<i  title='删除' class='fa fa-trash-o fa-lg'></i></a>";
                        
                      
                      return href;

                    }
                }


            ],
     drawCallback: function( settings ) {
         

           },

           initComplete:function(data){

//选中行
 $('#myTable tbody').on( 'click', 'tr', function () {
          
        if ( $(this).hasClass('selected') ) {
            $(this).removeClass('selected');
        }
        else {
            table.$('tr.selected').removeClass('selected');
            $(this).addClass('selected');
        }
        
    } );

//全选、反选
$('#allChecked').on('click' , function(){
  var boxes = document.getElementsByName("ids");
    for(i=0;i<boxes.length;i++){
                boxes[i].checked = this.checked;
    }
    var optIds ='';
    if(this.checked){
      $("input[name='ids']:checkbox:checked").each(function(){ 
      optIds+=$(this).val() +',';
       });
    }else{
  optIds='';
      }
      if(''!=optIds){
        optIds = optIds.substring(0,optIds.length-1);
      }
      $('#optIds').val(optIds);
});
           },
            Paginate: true, 
           language:{
               url: 'vendor/jquery/datatables/Chinese.json'
          }
    })
});  





//单条删除
  function goDelete(id){

      top.layer.confirm('您确定删除吗', function(index){
             var postInfoUrl = API_URL+"channel_epg";
            

          var infoUrl = API_URL+"channel_epg?query=delflag:0,Id:"+id;

          var formData =  MY_ASYNC_AJAX(infoUrl)[0];

           formData.Delflag = "0";

     $.ajax({
         url : postInfoUrl+'/'+id,
        type : 'delete',
         data: JSON.stringify(formData),
       cache : false,
     success : function(data) {
         
          $("#myTable").DataTable().ajax.reload().draw();
          top.layer.msg('删除成功');
          location.reload();
      }
    });
 top.layer.close(index);
      });
  }






</script>







